Skip to content

Add handling when all weights are zero in multinomial pmf#40

Merged
KOVALW merged 3 commits intomainfrom
wtk-importation-zero-prob
Mar 9, 2026
Merged

Add handling when all weights are zero in multinomial pmf#40
KOVALW merged 3 commits intomainfrom
wtk-importation-zero-prob

Conversation

@KOVALW
Copy link
Collaborator

@KOVALW KOVALW commented Mar 6, 2026

Improve prob_undetected_infections function by handling cases where the sum of weights is zero, which would arise in the case that the multinomial PMF is zero for all attempted combinations of known cases, known deaths, and undetected cases. Added corresponding tests to ensure correct behavior in these edge cases. This prevents potential division-by-zero errors and guarantees meaningful probability outputs even when all weights are zero.

Changes

  • Updated prob_undetected_infections in importation/perkins_et_al_methods.py to check if the sum of weights is zero; if so, it assigns equal probability to all rows instead of dividing by zero.
  • Added test_prob_undetected_infections_zero_probability_value to verify that when all weights are zero, the function returns a single row with probability 1.0 and weight 0.0.
  • Added test_sample_undetected_infections_zero_handling to ensure that sampling undetected infections works correctly when the zero-weight scenario occurs.

Copy link
Collaborator

@erik-rosenstrom erik-rosenstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It seems like to me that it might be useful to warn the user that their parameterization is improbable if the weights sampled from the PDF are so small as in the test related to rounding. I could imagine that being a tricky thing to diagnosis when trying to understand later down the line why the model is behaving a certain way since there is no error thrown.

@KOVALW KOVALW requested a review from erik-rosenstrom March 9, 2026 20:38
@KOVALW
Copy link
Collaborator Author

KOVALW commented Mar 9, 2026

Added issue #42 to address future log-level improvements to the module

Copy link
Collaborator

@erik-rosenstrom erik-rosenstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@KOVALW KOVALW merged commit 346fc0a into main Mar 9, 2026
4 checks passed
@KOVALW KOVALW deleted the wtk-importation-zero-prob branch March 9, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants